package com.huzz.component;

import cn.dev33.satoken.stp.StpInterface;
import com.huzz.entity.SysPermission;
import com.huzz.entity.SysRole;
import com.huzz.service.ISysPermissionService;
import com.huzz.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Name 用户角色/权限
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-04-2023/4/26 09:16
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private ISysRoleService roleService;

    @Autowired
    private ISysPermissionService permissionService;

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<SysRole> roleList = roleService.findRoleListByUserId(Integer.valueOf((String) loginId));

        return roleList.stream().map(r -> r.getName()).collect(Collectors.toList());
    }

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<SysPermission> permissionList = permissionService.findPermissionListByUserId(Integer.valueOf((String) loginId));

        return permissionList.stream().map(p -> p.getName()).collect(Collectors.toList());
    }

}
